package com.ysd.twocrm.controller;

import com.ysd.twocrm.entity.RoleModules;
import com.ysd.twocrm.entity.UserRoles;
import com.ysd.twocrm.mapper.RoleModulesMapper;
import com.ysd.twocrm.mapper.UserRolesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rolesmodules")
public class RolesModulesController {
@Autowired
     private RoleModulesMapper roleModulesMapper;

    /*
     * @Description 从前台传来的角色id先在角色模块表里给他处理掉也就是删除，接着在添加即可
     * @param mid 前台发送过来的模块数组，
     * @param roleid 前台发送过来的角色id
     * @return java.lang.String
     * @author liusupeng
     * @date 2020/4/15 17:10
     */
    @PutMapping
    public String getAllRoles(String mid,Integer roleid){
       roleModulesMapper.delModulesByRoleId(roleid);
        String[] split = mid.split(",");
        System.out.println(mid);
        for(int i=0;i<split.length;i++){
           roleModulesMapper.addModulesByRoleIdd(Integer.valueOf(split[i]),roleid);

        }
        return "success";
    }

}
